const gulp = require('gulp');

const concat = require('gulp-concat');
const hint = require('gulp-jshint');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();

var SCRIPT_PATH = "./src/js/**/*.js";
var STYLE_PATH = './src/style/*.scss';
var HTML_PATH = './src/**/*.html';

gulp.task('default', ['script', 'style', 'html'], () => {
    browserSync.init({
        server: {
            baseDir: './dest'
        }
    });

    gulp.watch(STYLE_PATH, ['style']);

    gulp.watch(SCRIPT_PATH, ['script']);

    gulp.watch(HTML_PATH, ['html']);

    //browserSync.reload();

    console.log('完成');
});

gulp.task('html', function () {
    return gulp.src(HTML_PATH)
        .pipe(gulp.dest('./dest'))
        .pipe(browserSync.stream());
});


gulp.task('script', function () {
    return gulp.src(SCRIPT_PATH)
        .pipe(hint())
        .pipe(hint.reporter('default'))
        .pipe(hint.reporter('fail'))
        .pipe(concat('index.js'))
        .pipe(uglify())
        .pipe(gulp.dest("./dest"))
        .pipe(browserSync.stream())
});

gulp.task('style', function () {
    return gulp.src(STYLE_PATH)
        .pipe(sass())
        .pipe(concat('style.css'))
        .pipe(gulp.dest('./dest'))
        .pipe(browserSync.stream())
});